<!DOCTYPE html>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%--<%@ taglib uri="/tld/authority.tld" prefix="authority" %>--%>
<%--<%@ taglib uri="/tld/token.tld" prefix="token" %>--%>
<div class="pop-background">
    <div class="col-md-5">
        <div class="popup popup5 popup-small x-4-move">
            <div class="panel-heading">
                <div class="panel-btns">
                    <a class="panel-close btn-4-hide">×</a>
                </div>
                <h3 class="panel-title">${empty department.id ? '新增' : '修改'}</h3>
            </div>
            <div class="panel-add-to">
                <div class="row">
                    <form>
                        <%--<token:token/>--%>
                        <input type="hidden" name="id" value="${department.id}">

                        <div class="panel-body panel-body-ws">
                            <div class="col-md-6">
                                <div class="form-group">
                                    <label class="col-sm-3 control-label"><em
                                            class="color-red btian">*</em>部门名称：</label>

                                    <div class="col-sm-6">
                                        <input type="text" class="form-control" name="name" value="${department.name}">
                                    </div>
                                </div>
                            </div>
                            <div class="col-md-6">
                                <div class="form-group">
                                    <label class="col-sm-3 control-label">上级部门：</label>

                                    <div class="col-sm-6">
                                        <div class="select-container select">
                                            <select class="select select-offscreen" name="pid">
                                                <option value="">-请选择-</option>
                                                <c:forEach items="${pList}" var="item">
                                                    <option value="${item.id}" ${item.id == department.pid ? 'selected' : ''}>${item.name}</option>
                                                </c:forEach>
                                            </select>
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </form>
                </div>

                <div class="btn-group2-s">
                    <div class="panel-body panel-body2">
                        <div class="btn-group2 left">
                            <authority:authority url="/dept/add,/dept/modify">
                                <button type="button" class="btn btn-primary btn-4-save">保存</button>
                            </authority:authority>
                            <button type="button" class="btn btn-default btn-4-hide">取消</button>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
    <script>
        $(document).ready(function () {

            $('#pop-wrapper select').select0();

            $('#pop-wrapper .x-4-move').dragging({
                move: 'both',
                randomPosition: false,
                handler: '.panel-heading'
            });

            $('#pop-wrapper .btn-4-save').off('click').on('click', function () {
                var id = $('#pop-wrapper input[name=id]').val();
                var url = 'dept/add.htm';
                if (id) {
                    url = 'dept/modify.htm';
                }
                ajaxSubmitResponseJSON({
                    url: url,
                    method: 'POST',
                    data: $('#pop-wrapper form').serialize(),
                    success: function (data) {
                        if (data.status == 0) {
                            closeLayer();
                            $('#data-wrapper .btn-4-query').trigger('click');
                        }
                    }
                });
            });
        });
    </script>
</div>